<?php

declare(strict_types=1);

namespace Core\Package\ElementPlus\FormCreate\FormItem;


class NumberInput extends FormItemAbstract
{
    protected string $_type = 'InputNumber';

    protected array $_style = [
        'width' => '100% !important'
    ];

    /**
     * 获取值类型
     * @return string
     */
    public function valueType(): string
    {
        return self::VALUE_TYPE_NUMBER;
    }

    /**
     * 默认组件参数
     * @return array
     */
    protected function defaultProps(): array
    {
        return [

        ];
    }


    public function __construct(string $field, string $title, $value = null)
    {
        $this->_title = $title;
        $this->_field = $field;
        $this->_value = $value;
    }


    /**
     * 设置是否自动获取焦点
     * @param bool $autofocus
     * @return NumberInput
     */
    public function autofocus(bool $autofocus): NumberInput
    {
        return $this->props('autofocus', $autofocus);
    }


    /**
     * 最大值
     * @param int|float $max
     * @return NumberInput
     */
    public function max(int|float $max): NumberInput
    {
        return $this->props('max', $max);
    }


    /**
     * 最小值
     * @param int|float $min
     * @return NumberInput
     */
    public function min(int|float $min): NumberInput
    {
        return $this->props('min', $min);
    }


    /**
     * 精确度
     * @param int $precision
     * @return NumberInput
     */
    public function precision(int $precision): NumberInput
    {
        return $this->props('precision', $precision);
    }


    /**
     * 表单提示
     * @param string $placeholder
     * @return NumberInput
     */
    public function placeholder(string $placeholder): NumberInput
    {
        return $this->props('placeholder', $placeholder);
    }


    /**
     * 表单是否只读
     * @param bool $readonly
     * @return NumberInput
     */
    public function readonly(bool $readonly): NumberInput
    {
        return $this->props('readonly', $readonly);
    }


    /**
     * 是否显示按钮
     * @param bool $showButton
     * @return NumberInput
     */
    public function showButton(bool $showButton): NumberInput
    {
        return $this->props('showButton', $showButton);
    }


    /**
     * 按钮改变值跨度
     * @param numeric $step
     * @return NumberInput
     */
    public function step($step): NumberInput
    {
        return $this->props('step', $step);
    }


    /**
     * 设置样式
     * @param array $style
     * @return $this
     */
    public function style(array $style): NumberInput
    {
        $this->_style = $style;
        return $this;
    }


    /**
     * 设置宽度
     * @param string $width
     * @return $this
     */
    public function width(string $width): NumberInput
    {
        $this->_style['width'] = $width.' !important';
        return $this;
    }
}